package com.ruyuan.rapid.common.config;

import lombok.Data;

import java.io.Serializable;
import java.util.Map;
import java.util.Objects;

/**
 * 服务定义类, 无论下游是什么样的服务,都需要通过这个模型进行注册
 * @author mac
 */
@Data
public class ServiceDefinition implements Serializable {

    /**
     * 唯一的服务ID serviceId:version
     */
    private String uniqueId;
    /**
     * 服务id
     */
    private String serviceId;
    /**
     * 服务版本号
     */
    private String version;
    /**
     * 服务的具体协议: http dubbo thrift
     */
    private String protocol;
    /**
     * 路径匹配规则, 访问真是ANT表达式
     * /user/login
     * /user/register
     * /user/getList
     */
    private String patternPath;
    /**
     * 环境名称 dev test prod
     */
    private String envType;
    /**
     * 服务启用禁用
     */
    private boolean enable = true;
    /**
     * 服务列表信息
     */
    private Map<String, ServiceInvoker> invokerMap;

    public ServiceDefinition() {
    }

    public ServiceDefinition(String uniqueId, String serviceId, String version, String protocol, String patternPath, String envType, boolean enable
            , Map<String, ServiceInvoker> invokerMap) {
        this.uniqueId = uniqueId;
        this.serviceId = serviceId;
        this.version = version;
        this.protocol = protocol;
        this.patternPath = patternPath;
        this.envType = envType;
        this.enable = enable;
        this.invokerMap = invokerMap;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        ServiceDefinition that = (ServiceDefinition) o;
        return Objects.equals(uniqueId, that.uniqueId);
    }

    @Override
    public int hashCode() {
        return Objects.hashCode(uniqueId);
    }
}
